//
//  MLZPlayListDeatlisController.m
//  MotherLover
//
//  Created by lanou on 15/12/31.
//  Copyright © 2015年 zj. All rights reserved.
//

#import "MLZPlayListDeatlisController.h"
#import "zJRequestManager.h"
#import "MLZPlayListDetalisModel.h"
#import "MLZPlayListDetalisModel.h"
#import "MLZPlayListTableViewCell.h"
#import "MLZPlayLastViewController.h"
@interface MLZPlayListDeatlisController()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *listArray;
@property (nonatomic, strong) UITableView *listTableView;
@end
@implementation MLZPlayListDeatlisController
- (void)viewDidLoad{

    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"%@",_zjid);
    [self passingData];
    [self addTableView];
    self.tabBarController.tabBar.hidden= YES;
}
- (void)passingData{
    NSString *str = [NSString stringWithFormat:@"http://app.beva.com/box-playlistItemData/p46/pl%@/kwerge--v2.0/page1-rp1000.json",_zjid];
    
    [zJRequestManager requestWithUrl:str parmDic:nil method:GET succeedWithData:^(NSData *data) {
     NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:(NSJSONReadingMutableContainers) error:nil];
     
        NSDictionary *allDic = dic[@"data"];
        NSArray *listDic = allDic[@"playlist"];
        _listArray = [NSMutableArray array];
        for (NSDictionary *onedic in listDic) {
            MLZPlayListDetalisModel *model= [[MLZPlayListDetalisModel alloc]init];
            [model setValuesForKeysWithDictionary:onedic];
            [_listArray addObject:model];
        }
        
        [_listTableView reloadData];
        NSLog(@"%@",_listArray);
    
    } failedWithError:^(NSError *connectionError) {
      NSLog(@"%@",connectionError);
   }];


}
- (void)addTableView{
    _listTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, KW, KH-64) style:(UITableViewStylePlain)];
    
    _listTableView.delegate = self;
    _listTableView.dataSource= self;
    
    _listTableView.rowHeight = 150;
    [self.view addSubview:_listTableView];
    
}
#pragma mark ---------tabelView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _listArray.count;

}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"ZJCell";
    MLZPlayListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[MLZPlayListTableViewCell alloc ]initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:identifier];
    }
    
    MLZPlayListDetalisModel *model = _listArray[indexPath.row];
    
    cell.model =model;


    return cell;



}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    MLZPlayLastViewController *lastView = [[MLZPlayLastViewController alloc]init];
    MLZPlayListDetalisModel *model = _listArray[indexPath.row];
    lastView.zjId = model.zjId;
    [self.navigationController pushViewController:lastView animated:YES];
    






}
-(void)didReceiveMemoryWarning{

    [super didReceiveMemoryWarning];

}
@end
